package controller;

import java.util.LinkedList;
import controller.command.Command;

public class Control {
	
	private LinkedList<Command> history;
	
	private static final Control ctrl = new Control();
	
	private Control(){
		history = new LinkedList<Command>();
	}
		
	public void storeAndExecute(Command cmd) {
		this.history.add(cmd); 
		cmd.execute();
	}

	public static Control getInstance() {
		return ctrl;
	}

	public void undoLastCommand() {
		if(!history.isEmpty()) {
			this.history.getLast().undo();
			this.history.removeLast();
		}
	}
}
